<?php
/**
 * 自动加载 class/interface
 *
 * @filesource spl_autoload.func.php
 * @package peck
 * @subpackage spl_autoload
 * @version $id: 0.2, utf8, Tue Dec 15 20:53:39 CST 2009
 * @author LD King <kldscs[at]gmail.com>
 * @copyright Copyleft (D.) 2007 - 2010 MiFunny China Inc.
 * @link http://mifunny.info/
 */

// 检测SPL autoload, 定义常量
if (!function_exists('spl_autoload_register')){
	exit('peck failed: spl_autoload does not exist in this PHP installation.');
}else{
	defined('PECK_DIR') or define('PECK_DIR', dirname(dirname(__FILE__)) );
	defined('DS') or define('DS',DIRECTORY_SEPARATOR);
}

if(false === spl_autoload_functions()){
	if( function_exists('__autoload') ){
		spl_autoload_register('__autoload',false);
	}
}
spl_autoload_extensions('.php, .class.php, .interface.php');

/**
 * 自动加载 class/intarface
 * 
 * @param string $name 类名
 */
function _loader($name){
	$pClass = array(
		'_view'=>'_view/_view.class.php', 
		'_db'=>'_db/_db.class.php',
		'_pdo'=>'_db/_pdo.class.php',
		'_mysqli'=>'_db/_mysqli.class.php',
		'_mysql'=>'_db/_mysql.class.php',
		);

	if( empty($pClass[$name]) ){ //array_key_exists($name, $pClass)
		$file = PECK_DIR.DS.$name.'.class.php';
	}else{
		$file = PECK_DIR.DS.$pClass[$name];
	}
    if( file_exists($file) ){
        include_once($file);
    }else throw new LogicException('('.__FUNCTION__.')Error: CLASS '.$name.' not found!');
}
spl_autoload_register('_loader');

?>
